#include "PlaneTest.h"

using physicsworks::math::Vec3;
using physicsworks::math::equal;

CPPUNIT_TEST_SUITE_REGISTRATION(PlaneTest);

void PlaneTest::setUp()
{
	p0f = new Plane<float>(Vec3<float>(2, 3, 1), Vec3<float>(3, 2, 1), Vec3<float>(5, 5, 1));
	p0d = new Plane<double>(Vec3<double>(2, 3, 1), Vec3<double>(3, 2, 1), Vec3<double>(5, 5, 1));
	
	p1f = new Plane<float>(Vec3<float>(0, 2, 3), Vec3<float>(0, -2, -1), Vec3<float>(8, 0, 1));
	p1d = new Plane<double>(Vec3<double>(0, 2, 3), Vec3<double>(0, -2, -1), Vec3<double>(8, 0, 1));
}

void PlaneTest::testGeneration()
{
	CPPUNIT_ASSERT(equal<float>(p0f->getNormal().x, 0));
	CPPUNIT_ASSERT(equal<float>(p0f->getNormal().y, 0));
	CPPUNIT_ASSERT(equal<float>(p0f->getNormal().z, 1));
	
	CPPUNIT_ASSERT(equal<double>(p0d->getNormal().x, 0));
	CPPUNIT_ASSERT(equal<double>(p0d->getNormal().y, 0));
	CPPUNIT_ASSERT(equal<double>(p0d->getNormal().z, 1));
	
	
	CPPUNIT_ASSERT(equal<float>(p1f->getNormal().x, 0));
	CPPUNIT_ASSERT(equal<float>(p1f->getNormal().y, -std::sqrt(2)/2));
	CPPUNIT_ASSERT(equal<float>(p1f->getNormal().z, std::sqrt(2)/2));
	
	CPPUNIT_ASSERT(equal<double>(p1d->getNormal().x, 0));
	CPPUNIT_ASSERT(equal<double>(p1d->getNormal().y, -std::sqrt(2)/2));
	CPPUNIT_ASSERT(equal<double>(p1d->getNormal().z, std::sqrt(2)/2));
	
	
	CPPUNIT_ASSERT(equal<float>(p0f->getDistance(), 1));
	CPPUNIT_ASSERT(equal<double>(p0d->getDistance(), 1));
	
	CPPUNIT_ASSERT(equal<float>(p1f->getDistance(), std::sqrt(2)/2));
	CPPUNIT_ASSERT(equal<double>(p1d->getDistance(), std::sqrt(2)/2));
}

void PlaneTest::tearDown()
{
	delete p0f;
	delete p0d;
	delete p1f;
	delete p1d;
}
